package com.itheima.d10_api_object;
/*
    Object类 :
        toString方法
        equals方法
 */

import java.util.Objects;

//学生类
class Student{
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public Student() {
    }
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}


public class Test1 {
    public static void main(String[] args) {
        //创建学生对象（给对象初始化成员变量数据的方式：1.setter方法    2.有参构造器）
        Student student = new Student();
        student.setName("熊大");
        student.setAge(10);
        //希望打印的数据信息是：对象中成员的数据值
        System.out.println(student);


        Student student2 = new Student("熊二",10);
        System.out.println(student2);

        //比较两个学生的年龄
//        if(student2.getAge() > student.getAge()){
//
//        }

        //equals比较两个对象是否相同： 比较对象中的年龄是否相同
        boolean result = student.equals(student2);
        System.out.println(result);
    }
}












